package com.shf.mapper;

import com.shf.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 持久层
 * @author 叶枫
 */
public interface ProductMapper {

    /**
     * @param product
     * 添加产品
     * @return int
     */
    @Insert("insert into product values (#{id},#{productNum},#{productName},#{cityName},#{departureTime},#{productPrice},#{productDesc},#{productStatus})")
    int addProduct(Product product);
    /**
     * @param productNum
     * 根据产品编号查询id
     * @return int
     */
    @Select("select product.id from product where productNum =#{productNum}")
    String selectProductByNum(String productNum);

    /**
     * 查询所有产品
     * @return
     */
    @Select("select * from product")
    List<Product> showAllProducts();

    /**
     * 根据id查询产品
     * @param id
     * @return
     */
    @Select("select * from product where id = #{id}")
    Product editById(String id);

    /**
     * 修改产品
     * @param product
     */
    @Select("update product set productNum = #{productNum},productName=#{productName}" +
            ", cityName=#{cityName}, departureTime=#{departureTime}" +
            ", productPrice=#{productPrice},productDesc=#{productDesc}," +
            "productStatus=#{productStatus}  where id=#{id}")
    void editProduct(Product product);

    /**
     * 根据id修改产品
     * @param id
     */
    @Delete("delete from product where id = #{id}")
    void deletePrductById(String id);


    /**
     * 多选删除
     * @param ids
     * @return
     */
    int deleteManyByIds(@Param("ids") String[] ids);


    /**
     * 查询所有的产品 id productName 开启
     * @return
     */
    @Select("select id,productName from product where productStatus = 1")
    List<Product>  findProducts();
}
